<?php

/**
 * @author huuvung
 * @copyright 2012
 */
 
defined('DSVH') or die('Restricted access');

//add 
function insertbangtin($local){
    mysql_query("insert bang_tin set 
    title = '".$local['title']."',
    alias = '".$local['alias']."',
    add_date = NOW(),
    content = '".$local['content']."'", dbconnect());
}

//list 
function getListbangtin($start,$limit)
    {
        $local_list = mysql_query("SELECT * FROM bang_tin
        limit ".(int)$start.",".(int)$limit."
        ", dbconnect());
        $result = array();
        while ($local = mysql_fetch_array($local_list)){
            $result []= $local;
        }
        return $result;
    }
//ham lay du lieu 
function getbangtin($id)
    {
    $pro = mysql_query("select * from bang_tin
    where id = '".(int)$id."'", dbconnect());
    return mysql_fetch_array($pro);
    }
    
function getinfo($alias)
    {
    $pro = mysql_query("select * from bang_tin
    where alias = '".$alias."'", dbconnect());
    return mysql_fetch_array($pro);
    }
    
//getListbangtinVoiThamSoNangCao

function getListbangtinVoiThamSoNangCao($local){
        $sql = "select * from bang_tin WHERE LCASE(title) like LCASE('%".$local['title']."%')";
         
        $local_list = mysql_query($sql, dbconnect());    
        
        $result = array();
        
        while ($local = mysql_fetch_array($local_list)){
          $result[] = $local;
        }
        return $result;
}

//cap nhat 
function editbangtin($id, $local)
{
    mysql_query("update bang_tin set
    title = '".$local['title']."',
    last_update = NOW(),
    content = '".$local['content']."'
    where id = '".(int)$id."'", dbconnect());
}
// xoa 
function delbangtin($id){
    mysql_query("delete from bang_tin where id ='".(int)$id."'", dbconnect());
}

function totalbangtin(){
   $result = mysql_query("select * from bang_tin",dbconnect());
   return mysql_num_rows($result);
}
    

?>